Make DOP brothers floats. Add writing to GPX. Refactor for commonality
authorrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 28 Jun 2005 22:02:22 +0000 (22:02 +0000)
committerrobertl <robertl@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 28 Jun 2005 22:02:22 +0000 (22:02 +0000)
and consistent handling of unknown values.

Course and speed are a problem in GPX.  Working with GPSXML guys now.

gpsbabel/defs.h
gpsbabel/gpx.c
gpsbabel/magproto.c
gpsbabel/waypt.c

index fb8b2dabcb6b5b8543ad04b4bc4b52e0addf1980..ef85b0ffcbedbb70efc3ff8c350faa612729e72f 100644 (file)
@@ -246,11 +246,11 @@ typedef struct {
        /* Optional dilution of precision:  positional, horizontal, veritcal.  
         * 1 <= dop <= 50 
         */ 
-       unsigned char hdop;             
-       unsigned char vdop;             
-       unsigned char pdop;             
-       signed short course;    /* Optional: degrees true */
-       signed int speed;       /* Optional: meters per second. */
+       float hdop;             
+       float vdop;             
+       float pdop;             
+       float course;   /* Optional: degrees true */
+       float speed;    /* Optional: meters per second. */
        
        geocache_data gc_data;
        xml_tag *gpx_extras;
index 4deb6a2b3d4089b1d63d44cc5cb4d5187d78a7da..fb9c45be052837b27f7bd61133af002c10d182d1 100644 (file)
@@ -1140,21 +1140,34 @@ write_gpx_url(const waypoint *waypointp)
 }
 
 /*
- * Write optional accuracty information for a given (way|track|route)point
+ * Write optional information for a given (way|track|route)point
  * to the output stream.  Done in one place since it's common for all three.
  * Order counts.
  */
 static void
-gpx_write_accuracy(const waypoint *waypointp)
+gpx_write_common(const waypoint *waypointp, const char *indent)
 {
+       write_gpx_url(waypointp);
+       write_optional_xml_entity(ofd, indent , "sym", waypointp->icon_descr);
+
        if (waypointp->hdop) {
-               fprintf(ofd, "  <hdop>%d</hdop>\n", waypointp->hdop);
+               fprintf(ofd, "%s<hdop>%f</hdop>\n", indent, waypointp->hdop);
        }
        if (waypointp->vdop) {
-               fprintf(ofd, "  <vdop>%d</vdop>\n", waypointp->vdop);
+               fprintf(ofd, "%s<vdop>%f</vdop>\n", indent, waypointp->vdop);
        }
        if (waypointp->pdop) {
-               fprintf(ofd, "  <pdop>%d</pdop>\n", waypointp->pdop);
+               fprintf(ofd, "%s<pdop>%f</pdop>\n", indent, waypointp->pdop);
+       }
+       if (gpx_wversion_num > 10) {
+               if (waypointp->course >= 0) {
+                       fprintf(ofd, "%s<course>%f</course>\n", 
+                               indent, waypointp->pdop);
+               }
+               if (waypointp->speed >= 0) {
+                       fprintf(ofd, "%s<speed>%f</speed>\n", 
+                               indent, waypointp->speed);
+               }
        }
 }
 
@@ -1197,8 +1210,7 @@ gpx_waypt_pr(const waypoint *waypointp)
                write_optional_xml_entity(ofd, "  ", "desc", waypointp->description);
        write_gpx_url(waypointp);
 
-       write_optional_xml_entity(ofd, "  ", "sym", waypointp->icon_descr);
-       gpx_write_accuracy(waypointp);
+       gpx_write_common(waypointp, "  ");
 
        fprint_xml_chain( waypointp->gpx_extras, waypointp );
        fprintf(ofd, "</wpt>\n");
@@ -1238,9 +1250,7 @@ gpx_track_disp(const waypoint *waypointp)
                        waypointp->shortname);
        }
        write_optional_xml_entity(ofd, "  ", "desc", waypointp->notes);
-       write_gpx_url(waypointp);
-       write_optional_xml_entity(ofd, "  ", "sym", waypointp->icon_descr);
-       gpx_write_accuracy(waypointp);
+       gpx_write_common(waypointp, "  ");
        fprintf(ofd, "</trkpt>\n");
 }
 
@@ -1285,8 +1295,7 @@ gpx_route_disp(const waypoint *waypointp)
        write_optional_xml_entity(ofd, "    ", "name", waypointp->shortname);
        write_optional_xml_entity(ofd, "    ", "cmt", waypointp->description);
        write_optional_xml_entity(ofd, "    ", "desc", waypointp->notes);
-       write_optional_xml_entity(ofd, "    ", "sym", waypointp->icon_descr);
-       gpx_write_accuracy(waypointp);
+       gpx_write_common(waypointp, "    ");
        fprintf(ofd, "  </rtept>\n");
 }
 
index 4e0898b0637c39f2a050d5edf01f161e6a5f3a32..8c91895d12c7f2319ff540cc28f12557cab42038 100644 (file)
@@ -894,7 +894,7 @@ mag_trkparse(char *trkmsg)
        struct tm tm;
        waypoint *waypt;
 
-       waypt  = xcalloc(sizeof *waypt, 1);
+       waypt  = waypt_new();
 
        memset(&tm, 0, sizeof(tm));
 
@@ -1089,7 +1089,7 @@ mag_wptparse(char *trkmsg)
        descr[0] = 0;
        icon_token[0] = 0;
 
-       waypt  = xcalloc(sizeof *waypt, 1);
+       waypt  = waypt_new();
 
        sscanf(trkmsg,"$PMGNWPL,%lf,%c,%lf,%c,%d,%c,%[^,],%[^,]", 
                &latdeg,&latdir,
index 14bbad644f9ac812b0223b6405af16b0d1e88885..ee8b433553dcb14a037275aa5e1922dd47c265f4 100644 (file)
@@ -1,7 +1,7 @@
 /*
     Perform various operations on waypoints.
 
-    Copyright (C) 2002 Robert Lipe, robertlipe@usa.net
+    Copyright (C) 2002-2005 Robert Lipe, robertlipe@usa.net
 
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -129,6 +129,8 @@ waypt_new(void)
 
        wpt = (waypoint *) xcalloc(sizeof (*wpt), 1);
        wpt->altitude = unknown_alt;
+       wpt->course = -999.0;
+       wpt->speed = -999.0;
 
        return wpt;
 }